package com.ohyes.bigbang.demo.springmail.controller;

import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ohyes.bigbang.commons.base.BaseController;
import com.ohyes.bigbang.demo.springmail.service.ISpringMailService;

@Controller
@RequestMapping("/springmail")
public class SpringMailController extends BaseController {

	private static final Logger logger = LoggerFactory
			.getLogger(SpringMailController.class);

	@Autowired
	ISpringMailService springMailService;

	@RequestMapping("/main")
	public String main(String content) {

		return "/demo/springmail/springmail";
	} 
	
	@RequestMapping("/send")
	public @ResponseBody
	HashMap<String, Object> sendMail(String content) {
		HashMap<String, Object> result = new HashMap<String, Object>();
		try {
//			System.getProperties().put( "proxySet", "true" );
//			System.getProperties().put( "proxyHost", "221.130.253.135" );
//			System.getProperties().put( "proxyPort", "8080" );
			springMailService.sendMail(content);
			result.put("sucess", true);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
			result.put("sucess", false);
			result.put("msg", e.getMessage());
		}

		return result;
	} 
}